Sarue.Error('facebook.js',[
	['FACEBOOK_ACCOUNT', 'Facebook application ID was not defined'],
	['FACEBOOK_ROOT', 'The "fb-root" div has not been created']
]);

Addons.Facebook = new Class({
	FBROOT: document.getElementById('fb-root'),
	FBAPPID: null,
	FBSTATUS: true,
	FBCOOKIE: true,
	FBXFBML: true,
	FBLOCALE: 'en_US',
    FBURL: '{protocol}://connect.facebook.net/{locale}/all.js',
	
	construct: function(){
		window.fbAsyncInit = this.fb_asyncInit;
		
		var body = document.getElementsByTagName('body');
		
		if (body[0] && !this.FBROOT)
		{
			this.FBROOT = document.createElement('div');
			this.FBROOT.id = 'fb-root';
			
			body[0].appendChild(this.FBROOT);
		}

        //Require facebook api
        Sarue.Require(Sarue.Tools.srpl(this.FBURL, {
            protocol: ('https:' == document.location.protocol ? 'https' : 'http'),
            locale: this.FBLOCALE
        }), false, false, true);
		
	},
	
	fb_asyncInit: function(){
		if(!this.FBAPPID)
			Sarue.Error.handler('FACEBOOK_ACCOUNT', null, 38);
			
		if(!this.FBROOT)
			Sarue.Error.handler('FACEBOOK_ROOT', null, 41);
			
		FB.init({
			appId: this.FBAPPID + '',
			status: this.FBSTATUS,
			cookie: this.FBCOOKIE,
			xfbml: this.FBXFBML
		});
	}
});